# 主要业务逻辑
from selenium.webdriver.common.by import By
from common.utils import utils
import time
from base.my_class import GetCarInvoiceInfoArgs
from common.api import driver_api


def getCarInvoiceInfo(args: GetCarInvoiceInfoArgs):
    driver = utils.create_new_driver()
    time.sleep(3)
    #driver.find_element(By.XPATH,"/html/body/div[3]/div[4]/div/ul/li[9]/a").click()
    #driver.find_element(By.XPATH,'//*[@id="N_DATAQUERY"]/a').click()
    driver_api.find_element(driver,By.XPATH,'//*[@id="N_DATAQUERY"]/a').click()
    #driver.find_element(By.XPATH,'//*[@id="1b7936e29aaa452398d64c74c9c88786"]/a').click()
    #driver.find_element(By.XPATH,'//*[@id="e9869d5792b041d881624924af9c1bc6"]/a').click()
    driver_api.find_element(driver,By.XPATH,'//*[@id="1b7936e29aaa452398d64c74c9c88786"]/a').click()
    driver_api.find_element(driver,By.XPATH,'//*[@id="e9869d5792b041d881624924af9c1bc6"]/a').click()
    time.sleep(3)
    startTime_input = driver_api.find_element(driver,By.XPATH,'//*[@id="startTime"]')
    endTime_input = driver_api.find_element(driver,By.XPATH,'//*[@id="endTime"]')

    js = 'arguments[0].removeAttribute("readonly");'
    driver.execute_script(js, startTime_input)
    driver.execute_script(js, endTime_input)
    startTime_input.send_keys(args.startTime)
    endTime_input.send_keys(args.endTime)
    #driver.find_element(By.XPATH,'//*[@id="exVehicleNum"]').send_keys(args.carPlate)
    driver_api.find_element(driver,By.XPATH,'//*[@id="passId"]').send_keys(args.passid)
    driver_api.find_element(driver,By.XPATH,'//*[@id="select"]').click()
    time.sleep(3)
    result = driver_api.find_elements_in_html(driver,"没有检索到符合条件的数据！")
    if(len(result) > 0):
        print("没有检索到符合条件的数据！")
    else:
        print("查询到数据")
        tr = driver.find_element(By.XPATH,'/html/body/div[4]/div[5]/div/div/div/div[3]/div[1]/table/thead')
        ths = tr.find_elements(By.TAG_NAME,"th")
        keys = []
        for th in ths:
            keys.append(th.text)
            print(th.text)
        tr1 = driver.find_element(By.XPATH,'/html/body/div[4]/div[5]/div/div/div/div[3]/div[2]/table/tbody/tr')
        
        th1s = tr1.find_elements(By.TAG_NAME,"td")
        values = []
        for th1 in th1s:
            values.append(th1.text)
            print(th1.text)
        print(keys)
        print(values)
        driver.find_element(By.XPATH,"/html/body/div[4]/div[5]/div/div/div/div[3]/div[2]/table/tbody/tr/td[19]/a").click()
        time.sleep(3)
        print("开始获取拆分数据")
        #body = driver.find_element(By.XPATH,"/html/body/div[6]/div/div/div[2]/table/tbody")
        body = driver.find_element(By.XPATH,'//*[@id="modal-dialog0"]/div/div/div[2]/table/tbody')
        
        chaifen_trs = body.find_elements(By.TAG_NAME,"tr")
        print(len(chaifen_trs),"行数")
        chaifen_data = []
        
        for chaifen_tr in chaifen_trs:
                chaifen_data_row = []
                chaifen_ths = chaifen_tr.find_elements(By.TAG_NAME,"td")
            
                for chaifen_th in chaifen_ths:
                    print(chaifen_th.text)
                    chaifen_data_row.append(chaifen_th.text)
                chaifen_data.append(chaifen_data_row)


        print(chaifen_data,"拆分数据")


    print(111)


def getCarPlateRecognition():
     

     return